﻿Public Class XRAYCLS
    Dim connect As CONDB = CONDB.NewConnection()
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub XRAYCLS_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SelectDatagridMasclsxray()

        DesignForm(Me)
        DesignGrid(MASCLSXRAYGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridMasclsxray()
        Dim objSelectDatamasclsxray As New MASCLSXRAY
        Dim masclsxrayData As DataTable
        masclsxrayData = connect.GetTable(objSelectDatamasclsxray.selectMasclsxray_)
        MASCLSXRAYGrid.PrimaryGrid.DataSource = masclsxrayData
    End Sub

    Private Sub MASCLSXRAYGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASCLSXRAYGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        Dim objEditData As New MASCLSXRAY
        grid = e.GridPanel.ActiveRow
        CXRYIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ID ประเภท").Value()
        CODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("CODE").Value()
        CXRYNAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อประเภท").Value()
        SXRYIDCTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("SXRYID").Value()
        XRYIDCTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("XRYID").Value()
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            MasClsxrayStatusChk.Checked = True
        Else
            MasClsxrayStatusChk.Checked = False
        End If

        connect = CONDB.NewConnection()
        If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
            Try
                Dim Sql As String
                connect.BeginTrans()
                Sql = "UPDATE masclsxray,xrayitem,maspartxray SET "
                If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then

                    Sql += "masclsxray.`status` ='1',xrayitem.`status` ='1',maspartxray.`status` ='1' "
                Else
                    Sql += "masclsxray.`status` ='0',xrayitem.`status` ='0',maspartxray.`status` ='0' "
                End If
                Sql += "WHERE  masclsxray.`cxryid` ='" & CXRYIDTxt.Text & "' AND  masclsxray.`cxryid` = maspartxray.`cxryid`  and masclsxray.`cxryid` = xrayitem.`cxryid` "

                connect.ExecuteNonQuery(Sql)
                connect.CommitTrans()
                'objEditData.editMasclsxrayData()
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            End Try
        End If
        connect.Dispose()
        addMasclsxray.Enabled = False
    End Sub

    Private Sub addMasclsxray_Click(sender As Object, e As EventArgs) Handles addMasclsxray.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If CODETxt.Text.ToString.Length > 0 And CXRYNAMETxt.Text.ToString.Length > 0 Then

                    Dim objInsertData As New MASCLSXRAY
                    objInsertData.CODE_ = CODETxt.Text
                    objInsertData.CXRYNAME_ = CXRYNAMETxt.Text
                    objInsertData.STATUS_ = MasClsxrayStatusChk.Checked
                    objInsertData.insertMasclsxrayData()

                    SelectDatagridMasclsxray()

                    CXRYIDTxt.Text = ""
                    CODETxt.Text = ""
                    CXRYNAMETxt.Text = ""
                    MasClsxrayStatusChk.Checked = False
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน", MsgBoxStyle.Critical)
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMasclsxray_Click(sender As Object, e As EventArgs) Handles editMasclsxray.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If CXRYIDTxt.Text.ToString.Length > 0 And CODETxt.Text.ToString.Length > 0 And CXRYNAMETxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลประเภทดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New MASCLSXRAY
                        objEditData.CXRYID_ = CXRYIDTxt.Text
                        objEditData.CODE_ = CODETxt.Text
                        objEditData.CXRYNAME_ = CXRYNAMETxt.Text
                        objEditData.STATUS_ = MasClsxrayStatusChk.Checked
                        objEditData.editMasclsxrayData()

                        SelectDatagridMasclsxray()

                        CXRYIDTxt.Text = ""
                        CODETxt.Text = ""
                        CXRYNAMETxt.Text = ""
                        MasClsxrayStatusChk.Checked = False
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน", MsgBoxStyle.Critical)
                End If
                addMasclsxray.Enabled = True
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("masclsxray")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("masclsxray")
        nextform.ShowDialog()
    End Sub
End Class